package com.tedu.studentmanagement.controller;

import com.tedu.studentmanagement.common.result.JsonResult;
import com.tedu.studentmanagement.common.result.StatusCode;
import com.tedu.studentmanagement.mapper.CourseMapper;
import com.tedu.studentmanagement.pojo.dto.CourseDTO;
import com.tedu.studentmanagement.pojo.vo.CourseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "课程模块")
@RestController
@RequestMapping("v1/cou")
public class CourseController {
    @Autowired
    private CourseMapper courseMapper;

    @ApiOperation("添加课程功能")
    @PostMapping("/insert")
    public JsonResult courseInsert(@RequestBody CourseDTO courseDTO){
        CourseVO courseVO = courseMapper.selectCourseById(courseDTO.getId());
        if (courseVO==null){
            courseMapper.insertCourse(courseDTO);
            return new JsonResult(StatusCode.OPERATION_SUCCESS);
        }else {
            return new JsonResult(StatusCode.OPERATION_FAILED);
        }
    }
}
